<% layout('/layouts/default.html', {title: '用户管理', libs: ['layout','zTree']}){ %>
<div class="ui-layout-west">
	<div class="card bd-0">
		<div class="card-header d-flex align-items-start justify-content-between box-header">
			<div class="pt-1">组织机构</div>
			<div class="d-flex">
				<button type="button" class="btn btn-xs btn-icon pd-5-f" id="btnExpand" title="展开" style="display:none;"><i class="la la-angle-up"></i></button>
				<button type="button" class="btn btn-xs btn-icon pd-5-f" id="btnCollapse" title="折叠"><i class="la la-angle-down"></i></button>
				<button type="button" class="btn btn-xs btn-icon pd-5-f" id="btnRefresh" title="刷新"><i class="la la-refresh"></i></button>
			</div>
		</div>
		<div class="card-body pd-10 ui-layout-content">
			<div id="tree" class="ztree"></div>
		</div>
	</div>
</div>
<div class="ui-layout-center">
	<iframe id="mainFrame" name="mainFrame" class="ui-layout-content pd-0" src="${ctx}/sys/empUser/list"></iframe>
</div>
<% } %>
<script>
// 初始化布局
$('body').layout({
	west__initClosed: false, // 是否默认关闭
	west__size: 180
});
// 主页框架
var win = $("#mainFrame")[0].contentWindow;
// 树结构初始化加载
var setting = {view:{selectedMulti:false},data:{key:{title:"title"},simpleData:{enable:true}},
	callback:{onClick:function(event, treeId, treeNode){
		tree.expandNode(treeNode);
		win.$('button[type=reset]').click();
		win.$('#officeCode').val(treeNode.id);
		win.page();
	}}
}, tree, loadTree = function(){
	js.ajaxSubmit("${ctx}/sys/office/treeData?___t=" + new Date().getTime(),
			{ctrlPermi:'${@Global.getConfig("user.adminCtrlPermi", "2")}'/*1拥有的权限 2管理的权限*/}, function(data){
		tree = $.fn.zTree.init($("#tree"), setting, data);//.expandAll(true);
		// 展开第一级节点
		var nodes = tree.getNodesByParam("level", 0);
		for(var i=0; i<nodes.length; i++) {
			tree.expandNode(nodes[i], true, false, false);
		}
		// 展开第二级节点
// 		nodes = tree.getNodesByParam("level", 1);
// 		for(var i=0; i<nodes.length; i++) {
// 			tree.expandNode(nodes[i], true, false, false);
// 		}
	}, null, null, "正在加载，请稍候...");
};loadTree();
// 工具栏按钮绑定
$('#btnExpand').click(function(){
	tree.expandAll(true);
	$(this).hide();
	$('#btnCollapse').show();
});
$('#btnCollapse').click(function(){
	tree.expandAll(false);
	$(this).hide();
	$('#btnExpand').show();
});
$('#btnRefresh').click(function(){
	loadTree();
});
</script>
</body></html>